package practice1_100;

import java.util.*;

public class Practice403 {
    //[1,2,2,1],[3,1,2],[1,3,2],[2,4],[3,1,2],[1,3,1,1],[6],[3,3],[4,1,1],[1,3,2],[2,4],[3,1,2],[1,3,1,1],[6],[3,3],[4,1,1],[1,3,2],[2,4],[3,1,2],[1,3,1,1],[6],[3,3],[4,1,1],[1,3,2],[2,4],[3,1,2],[1,3,1,1],[6],[3,3],[4,1,1],[1,3,2],[2,4],[3,1,2],[1,3,1,1],[6],[3,3],[4,1,1]
    public boolean canCross(int[] stones) {
//        Queue<Integer> queue=new LinkedList<>();
        int[][][] dpTable=new int[stones.length][stones.length][3];
//        Stack<Integer> stack=new Stack<>();
//        List<List<Integer>> list =new List<>();
//        Queue<Integer>  new LinkedList<Integer>();
        dpTable[1][0][0]=0;
        dpTable[1][0][1]=1;
        dpTable[1][0][2]=2;
        for (int i = 2; i <dpTable.length ; i++) {
            for (int j = i-1; j >=1; j--) {
                for (int k = 0; k < 3; k++) {
                    if(dpTable[i][j][k]>0&&stones[i]-stones[j]==dpTable[i][j][k]){
                        dpTable[i][j][0]=stones[i]-stones[j];
                        dpTable[i][j][1]=stones[i]-stones[j]-1;
                        dpTable[i][j][2]=stones[i]-stones[j]+1;
                    }
                    if(i== dpTable.length-1&&dpTable[i][j][k]>0){
                        return true;
                    }
                }
            }
        }
        return false;
    }

    public static void main(String[] args) {
//       boolean res= new Practice403().canCross(new int[]{0,1,3,6,10,13,15,18});
//        System.out.println(res);
//        [[100000000],[100000000],[100000000]]
        HashSet<Integer> set=new HashSet<>();
//        System.out.println(set.);
        List<List<Integer>> wall=new LinkedList<>();
        for (int i=0;i<3;i++){
            List<Integer> list=new LinkedList<>();
            list.add(100000000);
            wall.add(list);
        }

        int b=new Practice403().leastBricks(wall);
        System.out.println(b);
    }

    public int leastBricks(List<List<Integer>> wall) {
        if(wall.size()<=1) return 1;
        // if()
        int count=0;
        for(int i=0;i<wall.get(0).size();i++){
            count+= wall.get(0).get(i);
        }
        if(count==1) return wall.size();
        int res=Integer.MAX_VALUE;
        for(int i=1;i<count;i++){//总距离一个个加
            int temp=0;
            for(int j=0;j<wall.size();j++){
                int colCount=0;
                for(int k=0; k<wall.get(j).size();k++){
                    colCount+=wall.get(j).get(k);
                    if(colCount>i) {temp++;break;}
                    if(colCount==i) break;
                }
            }
            res=res>temp?temp:res;
        }
        return res;
    }
}
